/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * transfer.h
 *
 * Copyright (C) 2008, 2009 Lingtao Pan
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA 02111-1307, USA.
 */

#ifndef TRANSFER_H
#define TRANSFER_H

typedef struct _gftp_transfer gftp_transfer;

struct _gftp_transfer
{
    gftp_request *fromreq,
                 *toreq;

    GStaticMutex structmutex;   /* Protect the following variables */

    unsigned int cancel : 1,
        ready   : 1,
        started : 1,
        done : 1,
        show : 1,
        stalled : 1,
        stopped : 1,
        conn_error_no_timeout : 1;
  
    GList *files,
          *curfle,
          *updfle;


    GStaticMutex statmutex;     /* Protect the following variables */

    long numfiles,
         numdirs,
         current_file_number,
         current_file_retries;

    struct timeval starttime,
                   lasttime;

    double kbs;

    off_t curtrans,         /* Current transfered bytes for this file */
          curfsize,        /* Current file size */
          curresumed,       /* Resumed bytes for this file */

          trans_bytes,      /* Amount of data transfered for entire transfer */
          total_bytes,      /* Grand total bytes for whole transfer */
          resumed_bytes;    /* Grand total of resumed bytes for whole transfer */


    off_t accum_bytes;          /* Accumulated transfered bytes
                                   since last update on interface */
    double average_kbs;


    void *user_data;
    void *thread_id;
};


gftp_transfer* gftp_transfer_new ();
void     gftp_transfer_destroy        (gftp_transfer *transfer);
int      gftp_transfer_expand_dirs    (gftp_transfer *transfer);
gboolean gftp_transfer_is_active      (gftp_transfer *transfer);
off_t    gftp_transfer_transfer_file  (gftp_request  *fromreq, 
                                       const char *fromfile, 
                                       off_t fromsize, 
                                       gftp_request *toreq, 
                                       const char *tofile,   
                                       off_t tosize);

/* file list operation */
void     gftp_transfer_merge          (gftp_transfer *transfer, 
                                       gftp_transfer *trans_new);

void     gftp_transfer_remove_file    (gftp_transfer *transfer, 
                                       gftp_file *fle);

void     gftp_transfer_exchange_file_pos (gftp_transfer *transfer, 
                                          gftp_file *fle1, 
                                          gftp_file *fle2);


#endif
